<?php
class Esl extends WotHub
{
    public function creerTeam() {
        $this->addTemplate('eslcreate.tpl.php');
        $clanId = $_SESSION['clanInfo']['clan_id'];
        $this->ajouterScript('js/esl.js');
        $this->membres = Model_Clan::getMembresPseudo($clanId);
        if (isset($_POST['frm_name']) === true && $_POST['frm_name'] !== '' && isset($_POST['frm_type']) === true) {
            $esl = new Model_Esl($this->_pdo, $_SESSION['appId']);
            $esl->setEslTeam();
        }
        else if (count($_POST)>0){
            SmartbokMessage::addMessage(SmartbokMessage::ERR, 'Veuillez saisir le nom et le type de l\'équipe');
        }
    }
    
    public function GererTeam() {
        $this->addTemplate('eslgestion.tpl.php');
        $this->ajouterScript('js/esl.js');
        $clanId = $_SESSION['clanInfo']['clan_id'];
        $esl = new Model_Esl($this->_pdo, $_SESSION['appId']);
        if (isset($_POST['frm_eslid']) === true) {
            $esl->setEslTeam($_POST['frm_eslid']);
        }
        $this->teams = $esl->getTeams();
    }
    
    public function RechercherTeam() {
        $this->_pdo = new smartbokModele($this->bdd);
        $esl = new Model_Esl($this->_pdo, $this->appId);
        $team = $esl->getTeamInfo($this->params[0]);
        $membres = $esl->getTeamMembers($this->params[0]);
        foreach ($membres as $membre) {
            $lst[] = $membre['account_id'];
        }
        $pseudos = Model_Membre::getNickName(implode(',', $lst));
        header('Content-Type: text/xml');
        echo "<?xml version=\"1.0\"?>\n";
        echo "<esl>\n";
        echo '<donnees>';
        echo '<team><name>'.$team['esl_name'].'</name><type>'.$team['event_id'].'</type><typeName>'.$team['nom'].'</typeName></team>';
        echo '<membres>';
        foreach ($membres as $membre) {
            echo '<membre><account>'.$membre['account_id'].'</account><pseudo>'.$pseudos[$membre['account_id']]['nickname'].'</pseudo></membre>';
        }
        echo '</membres>';
        echo '</donnees>';
        echo "</esl>\n";
        $this->traiterAffichage = false;
        return true;
    }
    
    public function Strats() {
        $this->addTemplate('strats.tpl.php');
        $this->strats = array();
        $this->_addStrat(9);
    }

    private function _addStrat($type) {
        $esl = new Model_Esl($this->_pdo, $_SESSION['appId']);
        if (count($_POST) > 0) {
            if ($_POST['frm_nom'] !== '' && $_POST['frm_description'] !== '' && $_POST['frm_lien'] !== '') {
                $esl->enregistrerStrat($type);
            }
            else {
                SmartbokMessage::addMessage(SmartbokMessage::ERR, 'Veuillez saisir tous les champs.');
            }
        }
        $this->strats = $esl->getStratList($type);
    }
    public function ClaimGold() {
        $this->addTemplate('claimgold.tpl.php');
        $esl = new Model_Esl($this->_pdo, $_SESSION['appId']);
        $this->ajouterScript('js/claim.js');
        $this->teams = $esl->getTeams();
        
        
        $damage = 989.45;
        $frags = 1.07;
        $tier = 6.53;
        $spot = 1.53;
        $cap = 2.51;
        $def = 1.6;
        $er = $damage*(10/($tier + 2))*((0.22-$tier/100)+3*$tier/100);
        $er+= $frags*250;
        $er+= $spot*150;
        $er+=log($cap+1, 1.732)*150;
        $er+=$def*150;
        echo floor($er);
    }
}